package com.boatAnchorAssistant.service.controller.web;

import com.boatAnchorAssistant.pojo.param.role.*;
import com.boatAnchorAssistant.pojo.vo.role.*;
import com.boatAnchorAssistant.service.service.in.*;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import java.util.List;

/**
 *   web/角色
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 *
 */
@RestController
@RequestMapping("/role/web")
public class RoleWebController {

    private final RoleService service;

    public RoleWebController(RoleService service) {
        this.service = service;
    }


    /**
     * 创建角色
     * @param param
     * @return
     */
    @PostMapping("/createRole")
    public ApiResult createRole(@RequestBody @Valid CreateRoleParam param) {
        service.createRole(param);
        return ApiResult.ok();
    }


    /**
     * 修改角色
     * @param param
     */
    @PutMapping("/editRole")
    public ApiResult editRole(@RequestBody @Valid EditRoleParam param) {
        service.editRole(param);
        return ApiResult.ok();
    }

    /**
     * 移除角色
     * @param id
     */
    @DeleteMapping("/removeRole")
    public ApiResult removeRole(@RequestParam("id") Long id) {
        service.removeRole(id);
        return ApiResult.ok();
    }

    /**
     * 启动/禁用角色
     * @param id
     */
    @GetMapping("/enabledRole")
    public ApiResult enabledRole(@RequestParam("id") Long id) {
        service.enabledRole(id);
        return ApiResult.ok();
    }

    /**
     * 获取角色详情
     * @param id
     * @return
     */
    @GetMapping("/getRole")
    public ApiResult<GetRoleVo> getRole(@RequestParam("id") Long id) {
        GetRoleVo vo = service.getRole(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取角色列表
     * @param param
     * @return
     */
    @PostMapping("/getRoleList")
    public ApiResult<PageResult<GetRoleListVo>> getRoleList(@RequestBody GetRoleListParam param) {
        PageResult<GetRoleListVo> result = service.getRoleList(param);
        return ApiResult.ok(result);
    }


    /**
     * 获取角色下拉列表
     *
     * @return
     */
    @PostMapping("/getRoleDownList")
    public ApiResult<List<GetRoleDownListVo>> getRoleDownList(@RequestBody(required = false) @Valid GetRoleDownListParam param) {
        List<GetRoleDownListVo> list = service.getRoleDownList(param);
        return ApiResult.ok(list);
    }


}

